package org.cjlm.muaction.skin;
 
import org.cjlm.ui.pub.MAbstraction; 
import org.cjlm.ui.skin.SkinManager; 
import javax.swing.*; 
import java.awt.event.ActionEvent; 
 
public class SkinChangeAction extends MAbstraction {
    private final String skinId;
    
    public SkinChangeAction(String title, String skinId) {
        super(title);
        this.skinId  = skinId;
    }

    @Override
    public void doAction(ActionEvent e) throws Exception {
        SkinManager.applySkin(skinId);
        refreshAllUI();
    }

    private void refreshAllUI() {
        // 刷新主窗口
        SwingUtilities.updateComponentTreeUI(getDesktop().getTopLevelAncestor());

        // 刷新所有内部框架
        for (JInternalFrame frame : getDesktop().getAllFrames()) {
            SwingUtilities.updateComponentTreeUI(frame);
        }
    }
}